home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18src / dump.c < prev    next >
C/C++ Source or Header  |  1994-01-25  |  6KB  |  193 lines

  1. #ifndef lint
  2. static char Rcs_Id[] =
  3.     "$Id: dump.c,v 1.14 1994/01/25 07:11:27 geoff Exp $";
  4. #endif
  5.  
  6. /*
  7.  * dump.c - Ispell's dump mode
  8.  *
  9.  * This code originally resided in ispell.c, but was moved here to keep
  10.  * file sizes smaller.
  11.  *
  12.  * Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
  13.  * All rights reserved.
  14.  *
  15.  * Redistribution and use in source and binary forms, with or without
  16.  * modification, are permitted provided that the following conditions
  17.  * are met:
  18.  *
  19.  * 1. Redistributions of source code must retain the above copyright
  20.  *    notice, this list of conditions and the following disclaimer.
  21.  * 2. Redistributions in binary form must reproduce the above copyright
  22.  *    notice, this list of conditions and the following disclaimer in the
  23.  *    documentation and/or other materials provided with the distribution.
  24.  * 3. All modifications to the source code must be clearly marked as
  25.  *    such.  Binary redistributions based on modified source code
  26.  *    must be clearly marked as modified versions in the documentation
  27.  *    and/or other materials provided with the distribution.
  28.  * 4. All advertising materials mentioning features or use of this software
  29.  *    must display the following acknowledgment:
  30.  *      This product includes software developed by Geoff Kuenning and
  31.  *      other unpaid contributors.
  32.  * 5. The name of Geoff Kuenning may not be used to endorse or promote
  33.  *    products derived from this software without specific prior
  34.  *    written permission.
  35.  *
  36.  * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
  37.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  39.  * ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
  40.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  42.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  44.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  45.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  */
  48.  
  49. /*
  50.  * $Log: dump.c,v $
  51.  * Revision 1.14  1994/01/25  07:11:27  geoff
  52.  * Get rid of all old RCS log lines in preparation for the 3.1 release.
  53.  *
  54.  */
  55.  
  56. #include "config.h"
  57. #include "ispell.h"
  58. #include "proto.h"
  59.  
  60. void        dumpmode P ((void));
  61. static void    tbldump P ((struct flagent * flagp, int numflags));
  62. static void    entdump P ((struct flagent * flagp));
  63. static void    setdump P ((char * setp, int mask));
  64. static void    subsetdump P ((char * setp, int mask, int dumpval));
  65.  
  66. void dumpmode ()
  67.     {
  68.  
  69.     if (hashheader.flagmarker == '\\'
  70.       ||  hashheader.flagmarker == '#'
  71.       ||  hashheader.flagmarker == '>'
  72.       ||  hashheader.flagmarker == ':'
  73.       ||  hashheader.flagmarker == '-'
  74.       ||  hashheader.flagmarker == ','
  75.       ||  hashheader.flagmarker == '[') /* ] */
  76.     (void) printf ("flagmarker \\%c\n", hashheader.flagmarker);
  77.     else if (hashheader.flagmarker < ' '  ||  hashheader.flagmarker >= 0177)
  78.     (void) printf ("flagmarker \\%3.3o\n",
  79.      (unsigned int) hashheader.flagmarker & 0xFF);
  80.     else        
  81.     (void) printf ("flagmarker %c\n", hashheader.flagmarker);
  82.     if (numpflags)
  83.     {
  84.     (void) printf ("prefixes\n");
  85.     tbldump (pflaglist, numpflags);
  86.     }
  87.     if (numsflags)
  88.     {
  89.     (void) printf ("suffixes\n");
  90.     tbldump (sflaglist, numsflags);
  91.     }
  92.     }
  93.  
  94. static void tbldump (flagp, numflags)    /* Dump a flag table */
  95.     register struct flagent *    flagp;    /* First flag entry to dump */
  96.     register int        numflags; /* Number of flags to dump */
  97.     {
  98.  
  99.     while (--numflags >= 0)
  100.     entdump (flagp++);
  101.     }
  102.  
  103. static void entdump (flagp)        /* Dump one flag entry */
  104.     register struct flagent *    flagp;    /* Flag entry to dump */
  105.     {
  106.     register int        cond;    /* Condition number */
  107.  
  108.     (void) printf ("  flag %s%c: ",
  109.       (flagp->flagflags & FF_CROSSPRODUCT) ? "*" : " ",
  110.       BITTOCHAR (flagp->flagbit));
  111.     for (cond = 0;  cond < flagp->numconds;  cond++)
  112.     {
  113.     setdump (flagp->conds, 1 << cond);
  114.     if (cond < flagp->numconds - 1)
  115.         (void) putc (' ', stdout);
  116.     }
  117.     if (cond == 0)            /* No conditions at all? */
  118.     (void) putc ('.', stdout);
  119.     (void) printf ("\t> ");
  120.     (void) putc ('\t', stdout);
  121.     if (flagp->stripl)
  122.     (void) printf ("-%s,", ichartosstr (flagp->strip, 1));
  123.     (void) printf ("%s\n", flagp->affl ? ichartosstr (flagp->affix, 1) : "-");
  124.     }
  125.  
  126. static void setdump (setp, mask)    /* Dump a set specification */
  127.     register char *        setp;    /* Set to be dumped */
  128.     register int        mask;    /* Mask for bit to be dumped */
  129.     {
  130.     register int        cnum;    /* Next character's number */
  131.     register int        firstnz; /* Number of first NZ character */
  132.     register int        numnz;    /* Number of NZ characters */
  133.  
  134.     firstnz = numnz = 0;
  135.     for (cnum = SET_SIZE;  --cnum >= 0;  )
  136.     {
  137.     if (setp[cnum] & mask)
  138.         {
  139.         numnz++;
  140.         firstnz = cnum;
  141.         }
  142.     }
  143.     if (numnz == 1)
  144.     (void) putc (firstnz, stdout);
  145.     else if (numnz == SET_SIZE)
  146.     (void) putc ('.', stdout);
  147.     else if (numnz > SET_SIZE / 2)
  148.     {
  149.     (void) printf ("[^");
  150.     subsetdump (setp, mask, 0);
  151.     (void) putc (']', stdout);
  152.     }
  153.     else
  154.     {
  155.     (void) putc ('[', stdout);
  156.     subsetdump (setp, mask, mask);
  157.     (void) putc (']', stdout);
  158.     }
  159.     }
  160.  
  161. static void subsetdump (setp, mask, dumpval) /* Dump part of a set spec */
  162.     register char *        setp;    /* Set to be dumped */
  163.     register int        mask;    /* Mask for bit to be dumped */
  164.     register int        dumpval; /* Value to be printed */
  165.     {
  166.     register int        cnum;    /* Next character's number */
  167.     register int        rangestart; /* Value starting a range */
  168.  
  169.     for (cnum = 0;  cnum < SET_SIZE;  setp++, cnum++)
  170.     {
  171.     if (((*setp ^ dumpval) & mask) == 0)
  172.         {
  173.         for (rangestart = cnum;  cnum < SET_SIZE;  setp++, cnum++)
  174.         {
  175.         if ((*setp ^ dumpval) & mask)
  176.             break;
  177.         }
  178.         if (cnum == rangestart + 1)
  179.         (void) putc (rangestart, stdout);
  180.         else if (cnum <= rangestart + 3)
  181.         {
  182.         while (rangestart < cnum)
  183.             {
  184.             (void) putc (rangestart, stdout);
  185.             rangestart++;
  186.             }
  187.         }
  188.         else
  189.         (void) printf ("%c-%c", rangestart, cnum - 1);
  190.         }
  191.     }
  192.     }
  193.